def prime(x):
    h = True
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            h = False
            break
    return h

k = int(input())
if k < 1000 or k > 9999:
    print(0)
else:
    mm = str(k)
    mx = 0
    for o in range(len(mm)):
        for d in range(o + 1,len(mm) + 1):
            mun = int(mm[o:d])
            if prime(mun):
                mx = max(mx, mun)
    print(mx)
